//
//  AuthorizationStatus.m
//  CoolTennisBall
//
//  Created by CA on 16/3/31.
//  Copyright © 2016年 CoolLang. All rights reserved.
//

#import "AuthorizationStatus.h"
#import "FUIAlertView+customizeAppearance.h"
@import AVFoundation;
@import AssetsLibrary;

@implementation AuthorizationStatus

+ (BOOL)checkPhotoLibraryAuthorizationStatus
{
    ALAuthorizationStatus authorStatus = [ALAssetsLibrary authorizationStatus];
    if (authorStatus == ALAuthorizationStatusDenied || authorStatus == ALAuthorizationStatusRestricted) {
        
        [self showTipsAlertWithText:NSLocalizedString(@"Please allow this application to access the system album via -> \"Settings\" -> \"Privacy\" -> \"Photo\".", nil)];
        return NO;
    }
    
    return YES;
}

+ (BOOL)checkCameraAuthorizationStatus
{
    if (![UIImagePickerController isSourceTypeAvailable:(UIImagePickerControllerSourceTypeCamera)]) {
        
        [self showTipsAlertWithText:@"该设备不支持拍照"];
        
        return NO;
    }
    
    AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
    if (authStatus == AVAuthorizationStatusDenied || authStatus == AVAuthorizationStatusRestricted) {
        
        [self showTipsAlertWithText:NSLocalizedString(@"Please allow this application to access the system album via -> \"Settings\" -> \"Privacy\" -> \"Camera\".", nil)];
        
        return NO;
    }
    
    return YES;
}

+ (void)showTipsAlertWithText:(NSString *)message
{
    FUIAlertView *alertView = [[FUIAlertView alloc] initWithTitle:NSLocalizedString(@"Reminder", nil) message:message delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"Yes", nil), nil];
    [alertView customizeAppearance];
    [alertView show];
}

@end
